home *** CD-ROM | disk | FTP | other *** search
- Path: news.luc.edu!user
- From: VArase@varase.it.luc.edu (Verne Arase)
- Newsgroups: comp.lang.c
- Subject: Re: Borland C's tmpnam()
- Date: Sun, 31 Mar 1996 21:18:35 -0600
- Organization: LUMC
- Message-ID: <AD84A72B9668171739@mcdiala03.it.luc.edu>
- References: <AD75E5DC9668E2A52@mcdiala13.it.luc.edu> <Pine.A32.3.91.960322134158.23347A-100000@red.weeg.uiowa.edu> <AD78E5E796681EC58@mcdialb10.it.luc.edu> <827626790snz@genesis.demon.co.uk> <Pine.SOL.3.90.960324183336.6304B-100000@eddie> <828277392snz@genesis.demon.co.uk>
- NNTP-Posting-Host: 147.126.240.103
-
- In article <828277392snz@genesis.demon.co.uk>,
- Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
-
- >>This leads me to believe that the file names produced by tmpnam could
- exist
- >>but they are of a specific pattern which you can avoid. For example, gcc
- on
- >>OS/2 produces the filenames 10000000.tmp, 10000001.tmp, etc. So you
- should
- >>avoid using filenames ending in .tmp in OS/2.
- >
- >That might be reasonable for implementation to do but there is no
- >such guarantee in the standard.
-
- The file names returned by Borland C's tmpnam() are in the form
- "tmp%u.$$$", and do insure that the file name is unique in the current
- directory.
-
- This is the version I'm using now which allows specification of a target
- directory:
-
- -------
-
- /*
- Function name: tempname.c
-
- Function: Return unique file name for target directory
-
- Language: This program was compiled using Borland C Version 4.5.2
-
- */
-
- #include <stdio.h>
- #include <dir.h>
- #include <ctype.h>
- #include "IPUtil.h"
-
-
- Boolean /* return a temporary file name */
- tempname(
-
- /* parameters */
- Byte *where, /* drive:directory */
- Byte *filename) /* returned file name */ {
-
- /* local variables */
- Byte svl[MAXDRIVE], /* specification volume */
- sdr[MAXDIR], /* specification directory */
- sfl[MAXFILE], /* specification file name */
- sex[MAXEXT], /* specification extension */
- tvl[MAXDRIVE], /* tmpnam volume */
- tdr[MAXDIR], /* tmpnam directory */
- tfl[MAXFILE], /* tmpnam file name */
- tex[MAXEXT], /* tmpnam extension */
- odir[MAXDIR]; /* old directory */
- int odsk, /* old disk */
- what; /* attributes */
- Boolean err=False; /* error */
-
- /* begin of code */
- odsk=getdisk(); /* get current disk */
- what=fnsplit(where, /* get specified directory */
- svl,sdr,sfl,sex);
- if (what&DRIVE) /* if user specified drive ... */
- setdisk(toupper(svl[0])-'A'); /* set disk */
- if (!getcurdir(0,odir)) { /* if no error getting the cur dir ... */
- if (what&DIRECTORY) { /* if user specified directory ... */
- if (!chdir(sdr)) { /* if directory reset ... */
- tmpnam(filename); /* set file name */
- if (chdir(odir)) /* if error resetting dir ... */
- err=True; /* set error */
- }
- else err=True; /* else error */
- }
- else tmpnam(filename); /* else use current directory */
- }
- else err=True; /* else error */
- setdisk(odsk); /* reset default disk */
- if (!err) { /* if no error ... */
- what=fnsplit(filename, /* split tmpnam */
- tvl,tdr,tfl,tex);
- fnmerge(filename, /* merge temporary name */
- svl,sdr,tfl,tex);
- }
- return err; /* return error status */
- } /* tempname */
-
-
- ---
- The above are my own opinions, and not those of my employer.
-